<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta charset="UTF-8">
		<title>失物招领后台管理</title>
		<script type="text/javascript" src="../js/jquery.js"></script>
		<script src="../js/jquery.min.js" type="text/javascript"></script>
		<link rel="stylesheet" href="../css/bootstrap.css" />
		<link rel="stylesheet" href="../css/bootstrap.min.css" />
		<link rel="stylesheet" href="../css/main.css" />
		<link rel="stylesheet" href="../css/admain.css" />
		<script type="text/javascript" src="../js/bootstrap.js"></script>
		<script type="text/javascript" src="../js/scrollspy.js"></script>
		<link href="../fonts/css/font-awesome.css" rel="stylesheet">

		<!-- Toastr style -->
		<link href="../css/toastr.min.css" rel="stylesheet">

		<link href="../css/animate.css" rel="stylesheet">
		<link href="../css/style.css" rel="stylesheet">
		<!--sweetalert-->
		<link rel="stylesheet" href="../css/sweetalert.css" />
	</head>

	<body>
		<div id="wrapper">
			<!--左侧导航栏-->
			<nav class="navbar-default navbar-static-side" role="navigation">
				<div class="sidebar-collapse">
					<ul class="nav metismenu" id="side-menu">
						
						<li>
							<a href="#"><i class="fa fa-th-large"></i> <span class="nav-label">信息管理</span> <span class="fa arrow"></span></a>
							<ul class="nav nav-second-level collapse">
								
								<li>
									<a href="matchitem.jsp">招领配对</a>
								</li>
								<li>
									<a href="findingrecord.jsp">招领记录</a>
								</li>
							</ul>
						</li>
						
					</ul>

				</div>
			</nav>
			<!--
            	作者：1462859532@qq.com
            	时间：2017-03-29
            	描述：右侧导航栏
            -->
			<div id="page-wrapper" class="gray-bg">
				<div class="row border-bottom">
					<nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
						<div class="navbar-header">
							<a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i class="fa fa-bars"></i> </a>
						</div>
						<ul class="nav navbar-top-links navbar-right">
							<li>
								<span class="m-r-sm text-muted welcome-message">欢迎来到失物招领后台管理</span>
							</li>
							<li>
								<a href="login.jsp">
									<i class="fa fa-sign-out"></i> 注销
								</a>
							</li>
						</ul>
					</nav>
				</div>
				<div class="row wrapper border-bottom white-bg page-heading">
					<div class="col-lg-10">
						<ol class="breadcrumb">
							<li>
								<a>信息管理</a>
							</li>
							<li class="active">
								<strong>招领</strong>
							</li>
						</ol>
					</div>
					<div class="col-lg-2">

					</div>
				</div>

				<div class="wrapper wrapper-content  animated fadeInRight article">

					<div class="row">

						<!--失物信息-->
						<div class="col-md-12">

							<div>
								<div class="pull-left">
									<select class="form-control" id="categotyappend">
										<option value="0">--请选择你的物品类型--</option>
									</select>
								</div>

								<div class="pull-right">
									<div class="input-group"><input placeholder="按描述查找" class="input-sm form-control" type="text" id="querybydesc"> <span class="input-group-btn">
                                        <button type="button" class="btn btn-sm btn-primary" id="query"> 查询</button> </span>
									</div>
								</div>
								<div class="pull-right">
									<input placeholder="按地点查找" class="input-sm form-control" type="text" id="querybyloc"> 
								</div>

								<br />

								<div class="losingadmin panel panel-default">
									<div class="panel-body">
										<table class="losingtable table table-striped" cellpadding="20px" cellspacing="5" id="losingshow">
											<thead>
												<tr class="active">
												<th style="width:20%">类型</th>
												<th style="width:20%">地点</th>
												<th style="width:20%">发布时间</th>
												<th style="width:20%">描述</th>
												<th style="width:20%">操作</th>
											</tr>
											</thead>
											<tbody id="findingitem">
											
												
											</tbody>
										</table>
									</div>

									<div class="panel-footer">
										<div id="pagerole">
											<nav aria-label="Page navigation">
									<ul class="pagination">
								<li id="findingpagevalue" style="display: none"></li>
								<li id="findingpagecount" style="display: none"></li>
								<li><a href="#" id="itemfirst">首页</a></li>
								<li><a href="#" id="itemprev">上一页</a></li>
								<li><a href="#" id="itemnext">下一页</a></li>
								<li><a href="#" id="itemlast">尾页</a></li>
							</ul>
								</nav>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>

			</div>
			<div class="footer">
				<div>
					<strong>Copyright</strong>版权所有 &copy; 2017
				</div>
			</div>

		</div>

		<!--模态框关闭-->
<div>
	<div class="modal fade" id="modeladd" tabindex="-1" role="dialog">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">物品详情</h4>
				</div>
				<div class="modal-body">
					<div class="form-group">
						<!--
                                	作者：1462859532@qq.com
                                	时间：2017-03-28
                                	描述：可以在上面做个表单验证
                                -->
						<label for="locname" class="control-label">图片</label> 
						<img id="imgpic" style="width:500px;height:300px"/>
					</div>
					
					<div class="form-group">
						<label for="phone" class="control-label" id="detail">详情描述</label>
					</div>
				</div>
				<div class="modal-footer">

					<button type="button" class="btn btn-default" id="addclose"
						data-dismiss="modal">关闭</button>
				</div>
			</div>
		</div>
	</div>
</div>

<div>
	<div class="modal fade" id="finding" tabindex="-1" role="dialog">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">请填写招领信息</h4>
				</div>
				<div class="modal-body">
					<div class="form-group">
						<!--
                                	作者：1462859532@qq.com
                                	时间：2017-03-28
                                	描述：可以在上面做个表单验证
                                -->
						<label for="locname" class="control-label">招领人</label> 
						<input type="name" class="form-control disabled" id="username" placeholder="" > 
					</div>
					
					<div class="form-group">
						<label for="phone" class="control-label" id="detail">招领联系方式</label>
						<input type="name" class="form-control disabled" id="findingphone" placeholder="" > 
					</div>
				</div>
				<div class="modal-footer">
                    <button type="button" class="btn btn-default" 
						data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-default" id="findingadd"
						data-dismiss="modal">提交</button>
				</div>
			</div>
		</div>
	</div>
</div>

		<!-- Mainly scripts -->
		<script src="../js/jquery.js"></script>
		<script src="../js/bootstrap.min.js"></script>
		<script src="../js/jquery.metisMenu.js"></script>
		<script src="../js/jquery.slimscroll.min.js"></script>

		<!-- Custom and plugin javascript -->
		<script src="../js/inspinia.js"></script>
		<script src="../js/pace.min.js"></script>
		<script type="text/javascript" src="../js/sweetalert.min.js"></script>
		<script type="text/javascript">
		   $(function(){
			   $.ajax({
		    		 type:"post",
		    		 url:"../user/allcategory.action",
		    		 dataType:"json",
		    		 success:function(data){
		    			 for(var i=0;i<data.length;i++){
		    				 $("#categotyappend").append("<option value="+data[i].categoryID+">"+data[i].categoryName+"</option>");
		    			 }
		    			
		    		 }
		    	 });
			   $.ajax({
					type:"post",
					url:"../admin/confirmbycondition.action",
					dataType:"json",
					success:function(data){
						 if(data.pickInfo.length>=5){
		    				  length=5;
		    			  }else{
		    				  length=data.pickInfo.length;
		    			  }
		    			  for(var i=0;i<length;i++){
		    				  if(data.pickInfo[i].itemlocation==null){
		    					  data.pickInfo[i].itemlocation="无";
		    				  }
		    				  if(data.pickInfo[i].itemsDescription==null){
		    					  data.pickInfo[i].itemsDescription="无";
		    				  }
		    				  $("#findingitem").append('<tr><td style="display: none;">'+
		    						  data.pickInfo[i].pickingID+'</td><td>'+
		    						  data.pickInfo[i].categoryName+'</td><td>'+
		    						  data.pickInfo[i].itemlocation+'</td><td>'+
		    						  data.pickInfo[i].pickerTime+'</td><td>'+
		    						  data.pickInfo[i].itemsDescription+'</td><td><a  class="btn btn-primary agree" onclick="view(this)">查看详情</a>'+
		    						  '<button class="btn btn-success cancel" onclick="sure(this)">确认招领</button></td></tr>');
		    				  $("#findingpagevalue").text(data.currentpage);
		    			  }
		    			  $("#findingpagecount").text(data.count);
					}
				});
			   $("#itemfirst").click(function(){
		    		 var categotyappend=$("#categotyappend").find("option:selected").val();
		    		 if(categotyappend==0){
		    			 categotyappend=null;
		    		 }
		    		 var itemsDescription=$("#querybydesc").val();
		    		 var location=$("#querybyloc").val();
		    		  $.ajax({
	    				  type:"post",
			    		  url:"../admin/confirmbycondition.action?currentpage=0",
			    		  dataType:"json",
			    		  data:{"CategoryID":categotyappend,"description":itemsDescription,"location":location},
			    		  success:function(data){
			    			  $("#findingitem tr").remove();
			    			  if(data.pickInfo.length>=5){
			    				  length=5;
			    			  }else{
			    				  length=data.pickInfo.length;
			    			  }
			    			  for(var i=0;i<length;i++){
			    				  if(data.pickInfo[i].itemlocation==null){
			    					  data.pickInfo[i].itemlocation="无";
			    				  }
			    				  if(data.pickInfo[i].itemsDescription==null){
			    					  data.pickInfo[i].itemsDescription="无";
			    				  }
			    				  $("#findingitem").append('<tr><td style="display: none;">'+
			    						  data.pickInfo[i].pickingID+'</td><td>'+
			    						  data.pickInfo[i].categoryName+'</td><td>'+
			    						  data.pickInfo[i].itemlocation+'</td><td>'+
			    						  data.pickInfo[i].pickerTime+'</td><td>'+
			    						  data.pickInfo[i].itemsDescription+'</td><td><a  class="btn btn-primary agree" onclick="view(this)">查看详情</a>'+
			    						  '<button class="btn btn-success cancel" onclick="sure(this)">确认招领</button></td></tr>');
			    				  $("#findingpagevalue").text(data.currentpage);
			    			  }
			    			  $("#findingpagecount").text(data.count);
			    		  }
	    			  })
		    	  });
		    	  //上一页
		    	  $("#itemprev").click(function(){
		    		  var categotyappend=$("#categotyappend").find("option:selected").val();
			    	  var itemsDescription=$("#querybydesc").val();
			    	  var location=$("#querybyloc").val();
			    	  if(categotyappend==0){
			    			 categotyappend=null;
			    		 }
		    		  //alert(123);
		    		  //当前页
		    		  var pagecurrent=$("#findingpagevalue").text();
		    		  //总页数
		    		  var pagecount=$("#findingpagecount").text();
		    		  if(pagecurrent==0){
		    			  alert("不好意思，已经是第一页了");
		    		  }
		    		  else{
		    			  $.ajax({
		    				  type:"post",
				    		  url:"../admin/confirmbycondition.action?currentpage="+(parseInt(pagecurrent)-1),
				    		  dataType:"json",
				    		  data:{"CategoryID":categotyappend,"description":itemsDescription,"location":location},
				    		  success:function(data){
				    			  $("#findingitem tr").remove();
				    			  if(data.pickInfo.length>=5){
				    				  length=5;
				    			  }else{
				    				  length=data.pickInfo.length;
				    			  }
				    			  for(var i=0;i<length;i++){
				    				  if(data.pickInfo[i].itemlocation==null){
				    					  data.pickInfo[i].itemlocation="无";
				    				  }
				    				  if(data.pickInfo[i].itemsDescription==null){
				    					  data.pickInfo[i].itemsDescription="无";
				    				  }
				    				  $("#findingitem").append('<tr><td style="display: none;">'+
				    						  data.pickInfo[i].pickingID+'</td><td>'+
				    						  data.pickInfo[i].categoryName+'</td><td>'+
				    						  data.pickInfo[i].itemlocation+'</td><td>'+
				    						  data.pickInfo[i].pickerTime+'</td><td>'+
				    						  data.pickInfo[i].itemsDescription+'</td><td><a  class="btn btn-primary agree" onclick="view(this)">查看详情</a>'+
				    						  '<button class="btn btn-success cancel" onclick="sure(this)">确认招领</button></td></tr>');
				    				  $("#findingpagevalue").text(data.currentpage);
				    			  }
				    			  $("#findingpagecount").text(data.count);
				    		  }
		    			  })
		    		  }
		    		 // 
		    	  });
		    	  //下一页
		    	  $("#itemnext").click(function(){
		    		  var categotyappend=$("#categotyappend").find("option:selected").val();
			    	  var itemsDescription=$("#querybydesc").val();
			    	  var location=$("#querybyloc").val();
			    	  if(categotyappend==0){
			    			 categotyappend=null;
			    		 }
		    		  //当前页
		    		  var pagecurrent=$("#findingpagevalue").text();
		    		  //总页数
		    		  var pagecount=$("#findingpagecount").text();
		    		  if((parseInt(pagecurrent)+1)*5>=pagecount){
		    			  alert("不好意思，已经是最后一页了");
		    		  }else{
		    			  $.ajax({
		    				  type:"post",
				    		  url:"../admin/confirmbycondition.action?currentpage="+(parseInt(pagecurrent)+1),
				    		  dataType:"json",
				    		  data:{"CategoryID":categotyappend,"description":itemsDescription,"location":location},
				    		  success:function(data){
				    			  $("#findingitem tr").remove();
				    			  if(data.pickInfo.length>=5){
				    				  length=5;
				    			  }else{
				    				  length=data.pickInfo.length;
				    			  }
				    			  for(var i=0;i<length;i++){
				    				  if(data.pickInfo[i].itemlocation==null){
				    					  data.pickInfo[i].itemlocation="无";
				    				  }
				    				  if(data.pickInfo[i].itemsDescription==null){
				    					  data.pickInfo[i].itemsDescription="无";
				    				  }
				    				  $("#findingitem").append('<tr><td style="display: none;">'+
				    						  data.pickInfo[i].pickingID+'</td><td>'+
				    						  data.pickInfo[i].categoryName+'</td><td>'+
				    						  data.pickInfo[i].itemlocation+'</td><td>'+
				    						  data.pickInfo[i].pickerTime+'</td><td>'+
				    						  data.pickInfo[i].itemsDescription+'</td><td><a  class="btn btn-primary agree" onclick="view(this)">查看详情</a>'+
				    						  '<button class="btn btn-success cancel" onclick="sure(this)">确认招领</button></td></tr>');
				    				  $("#findingpagevalue").text(data.currentpage);
				    			  }
				    			  $("#findingpagecount").text(data.count);
				    		  }
		    			  })

		    		  }
		    	  });
		    	  //最后一页
		    	  $("#itemlast").click(function(){
		    		  var categotyappend=$("#categotyappend").find("option:selected").val();
			    	  var itemsDescription=$("#querybydesc").val();
			    	  var location=$("#querybyloc").val();
			    	  if(categotyappend==0){
			    			 categotyappend=null;
			    		 }
		    		  var last;
		    		  if(parseInt($("#findingpagecount").text())%5!=0){
		    			  last=parseInt(parseInt($("#findingpagecount").text())/5);
		    		  }else{
		    			  last=parseInt($("#findingpagecount").text())/5-1;
		    		  }
		    		  $.ajax({
	    				  type:"post",
			    		  url:"../admin/confirmbycondition.action?currentpage="+last,
			    		  data:{"CategoryID":categotyappend,"description":itemsDescription,"location":location},
			    		  dataType:"json",
			    		  success:function(data){
			    			  $("#findingitem tr").remove();
			    			  if(data.pickInfo.length>=5){
			    				  length=5;
			    			  }else{
			    				  length=data.pickInfo.length;
			    			  }
			    			  for(var i=0;i<length;i++){
			    				  if(data.pickInfo[i].itemlocation==null){
			    					  data.pickInfo[i].itemlocation="无";
			    				  }
			    				  if(data.pickInfo[i].itemsDescription==null){
			    					  data.pickInfo[i].itemsDescription="无";
			    				  }
			    				  $("#findingitem").append('<tr><td style="display: none;">'+
			    						  data.pickInfo[i].pickingID+'</td><td>'+
			    						  data.pickInfo[i].categoryName+'</td><td>'+
			    						  data.pickInfo[i].itemlocation+'</td><td>'+
			    						  data.pickInfo[i].pickerTime+'</td><td>'+
			    						  data.pickInfo[i].itemsDescription+'</td><td><a  class="btn btn-primary agree" onclick="view(this)">查看详情</a>'+
			    						  '<button class="btn btn-success cancel" onclick="sure(this)">确认招领</button></td></tr>');
			    				  $("#findingpagevalue").text(data.currentpage);
			    			  }
			    			  $("#findingpagecount").text(data.count);
			    		  }
	    			  })
		    	  });
		    	  
		   })

		   var sureid;
		   function sure(e){
		    		  sureid=$(e).parent().parent().children(":first").text();
		    		  //alert(sureid);
		    		  $("#finding").modal('show');
		    		  /*
		    		  */
		    	  }
		   
		   $("#query").click(function(){
			      var categotyappend=$("#categotyappend").find("option:selected").val();
		    	  var itemsDescription=$("#querybydesc").val();
		    	  var location=$("#querybyloc").val();
		    	  if(categotyappend==0){
		    			 categotyappend=null;
		    		 }
	    		 
	    		  $.ajax({
 				  type:"post",
		    		  url:"../admin/confirmbycondition.action",
		    		  data:{"CategoryID":categotyappend,"description":itemsDescription,"location":location},
		    		  dataType:"json",
		    		  success:function(data){
		    			  $("#findingitem tr").remove();
		    			  if(data.pickInfo.length>=5){
		    				  length=5;
		    			  }else{
		    				  length=data.pickInfo.length;
		    			  }
		    			  for(var i=0;i<length;i++){
		    				  if(data.pickInfo[i].itemlocation==null){
		    					  data.pickInfo[i].itemlocation="无";
		    				  }
		    				  if(data.pickInfo[i].itemsDescription==null){
		    					  data.pickInfo[i].itemsDescription="无";
		    				  }
		    				  $("#findingitem").append('<tr><td style="display: none;">'+
		    						  data.pickInfo[i].pickingID+'</td><td>'+
		    						  data.pickInfo[i].categoryName+'</td><td>'+
		    						  data.pickInfo[i].itemlocation+'</td><td>'+
		    						  data.pickInfo[i].pickerTime+'</td><td>'+
		    						  data.pickInfo[i].itemsDescription+'</td><td><a  class="btn btn-primary agree" onclick="view(this)">查看详情</a>'+
		    						  '<button class="btn btn-success cancel" onclick="sure(this)">确认招领</button></td></tr>');
		    				  $("#findingpagevalue").text(data.currentpage);
		    			  }
		    			  $("#findingpagecount").text(data.count);
		    		  }
 			  })
 			  
 			 
		   })
		    function view(e){
			          var id=$(e).parent().parent().children(":first").text();
	    			  $("#modeladd").modal('show');
	    			  $("#detail").text("");
	    			  $.ajax({
	    				  type:"post",
	    				  url:"../user/pickdetail.action?picid="+id,
	    				  dataType:"json",
	    				  success:function(data){
	    					  $("#imgpic").attr("src","/pic/"+data.picture);
	    					  $("#detail").append(data.detaildescritton);
	    				  },
	    				  error:function(){
	    					  swal("不好意思", "查看失败)", "error");
	    				  }
	    			  })
	       }
		   
		   $("#findingadd").click(function(){
			   //alert(sureid);
			   $.ajax({
				   type:"post",
				   url:"../admin/insertfinding.action",
				   data:{"UserName":$("#username").val(),"Phone":$("#findingphone").val(),"PickingID":sureid},
				   dataType:"json",
				   success:function(data){
					    $.ajax({
							type:"post",
							url:"../admin/confirmitem.action?id="+sureid,
							dataType:"json",
							success:function(data){
								if(data==1){
								swal("成功!", "招领此物品", "success");
								}else{
									swal("失败", "请查看数据是否正确", "error");
									
								}
							},
							error:function(){
								swal("失败", "请查看数据是否正确", "error");
							}
						})				  			
				   },
				   error:function(){
					   swal("失败", "请查看数据是否正确", "error");
				   }
			   })
		   })
		</script>
	</body>

</html>